<?php

namespace App\BO\Wechat;

use EasyWeChat\Factory;
use EasyWeChat\Payment\Application as Payment;

class WechatFactory
{
    /**
     * @var Payment
     */
    protected static $payment;

    /**
     * @return Payment
     */
    public static function payment()
    {
        if (!is_null(self::$payment)) {
            return self::$payment;
        }

        $config = config('wechat.payment.default');
        $config['notify_url'] = env('APP_URL') . '/wechat/notify/pay';
        /*
        $config['oauth'] = [
            'scopes' => ['snsapi_userinfo'],
            'callback' => '/wechat/callback',
        ];
        */

        $payment = Factory::payment($config);
        self::$payment = $payment;

        return self::$payment;
    }
}
